<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../common.inc" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="./css/style1.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="./js/form.js"></script>
<script type="text/javascript" language="javascript">
<!--
	function checkForm(){
		var objs = document.getElementsByName("roleId");
		var num = 0;
		for(var i = 0; i < objs.length; i++){
			if(objs[i].checked)num = num + 1;
		}
		if(num == 0){
			alert("<fmt:message key='common.message.wDelete'/>");
			return false;
		}
		return true;
	}
	
	function checkForm2(){
		var objs = document.getElementsByName("roleId");
		var sign = 0;
		for(var i = 0; i < objs.length; i++){
			if(objs[i].value != 0 && objs[i].checked)sign = sign + 1;
		}
		if(sign <= 0){
			alert("请选择待操作的项！");
			return false;
		}else if(sign > 1){
			alert("只能选择一个待操作项！");
			return false;
		}
		return true;
	}

	function viewRoleUser(){
		if(checkForm2()){
			var objs = document.getElementsByName("roleId");
			var id = 0;
			for(var i = 0; i < objs.length; i++){
				if(objs[i].value != 0 && objs[i].checked){
					id = objs[i].value;
					break;
				}
			}
			window.location.href = "./role.do?action=viewRoleUsers&roleId="+id;
			window.location.target = "main";
		}
	}
	
	function addRole(){
		window.location.href = "./role.do?action=preAddRole";
		window.location.target = "main";
	}
	
	function updateRole(){
		if(checkForm2()){
			var objs = document.getElementsByName("roleId");
			var id = 0;
			for(var i = 0; i < objs.length; i++){
				if(objs[i].value != 0 && objs[i].checked){
					id = objs[i].value;
					break;
				}
			}
			window.location.href = "./role.do?action=preUpdateRole&id="+id;
			window.location.target = "main";
		}
	}
	function addViewRole(){
		window.location.href = "./role.do?action=preAddViewRole";
		window.location.target = "main";
	}
	
	function updateViewRole(){
		if(checkForm2()){
			var objs = document.getElementsByName("roleId");
			var id = 0;
			for(var i = 0; i < objs.length; i++){
				if(objs[i].value != 0 && objs[i].checked){
					id = objs[i].value;
					break;
				}
			}
			window.location.href = "./role.do?action=preUpdateViewRole&id="+id;
			window.location.target = "main";
		}
	}
	
	function viewRole(id){
		window.location.href = "./role.do?action=viewRole&id="+id;
		window.location.target = "main";
	}
	
	function deleteRole(){
		if(checkForm()){
			if(confirm("<fmt:message key='common.message.delete'/>")){
				document.roleForm.action = "./role.do?action=deleteRole";
				document.roleForm.target = "main";
				document.roleForm.submit();
			}
		}
	}
	
	function initPage(result){
		if(result == 1){
			alert("<fmt:message key='common.message.deleteSuccess'/>");
		}
	}
-->
</script>
</head>
<body onload="initPage('${result}')">
<form name="roleForm" action="" method="post">
	<table class="table_frame">
		<tr>
			<td>
				<table class="table_title1">
					<tr>
						<td class="title_lab" colspan="2"><fmt:message key='role.title.main'/></td>
					</tr>
					<tr>
						<td valign="bottom" class="a_tools" style="padding-left: 3px;">
							<a href="javascript:viewRoleUser();" title="<fmt:message key='role.title.assignUser'/>" hidefocus="true"><fmt:message key='role.title.assignUser'/></a>
							|
							<a class="add" href="javascript:addRole();" title="<fmt:message key='common.button.add'/>" hidefocus="true"><fmt:message key='common.button.add'/></a>
							<a class="update" href="javascript:updateRole();" title="<fmt:message key='common.button.update'/>" hidefocus="true"><fmt:message key='common.button.update'/></a>
							<a class="del" href="javascript:deleteRole();" title="<fmt:message key='common.button.delete'/>" hidefocus="true"><fmt:message key='common.button.delete'/></a>
							<!--<a class="add" href="javascript:addViewRole();" title="<fmt:message key='common.button.add'/>" hidefocus="true">新增(自定义桌面)</a>
							--><!--<a class="update" href="javascript:updateViewRole();" title="<fmt:message key='common.button.update'/>" hidefocus="true">修改(自定义页面)</a>
						--></td>
						<td></td>
					</tr>
					<tr><td height="2"></td></tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>
				<table class="table_title2">
					<tr>
						<td class="title_lab"><fmt:message key='role.title.main'/></td>
					</tr>
					<tr>
						<td>
							<table class="table">
								<tr>
									<td valign="top">
										<!-- 
										<div style="width:800px;height:100%;overflow-x: scroll;overflow-y: hidden;">
										 -->
										<table class="table_style">
											<tr>
												<td class="title" width="8"></td>
												<td class="title" width="30"><fmt:message key='common.lable.checkbox'/></td>
												<td class="title" width="12%"><fmt:message key='role.lable.roleCode'/></td>
												<td class="title"><fmt:message key='role.lable.roleName'/></td>
												<td class="title"><fmt:message key='role.lable.roleDesc'/></td>
												<td class="title" width="12%"><fmt:message key='role.lable.maxLimitNum'/></td>
											</tr>
											<c:forEach var="role" items="${roles}">
											<c:if test="${role.roleCode != 'admin'}">
											<tr onmouseover="onmousemoveChange(this,'img${role.id}')" onmouseout="onmouseoutChange(this,'img${role.id}')">
												<td height="16" width="8" align="right"><img id="img${role.id}" src="./images/table_sign2.bmp"></td>
												<td align="center"><input id="roleId" name="roleId" type="checkbox" value="${role.id}"/></td>
												<td>${role.roleCode}</td>
												<td><a href="javascript:viewRole(${role.id});">${role.roleName}</a></td>
												<td>${role.roleDesc}</td>
												<td>${role.maxLimitNum}</td>
											</tr>
											</c:if>
											</c:forEach>
										</table>
										<!-- 
										</div>
										 -->
									</td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
</form>
</body>
</html>